import {defineConfig} from 'umi';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import gctjson from '../gct.env.json';

const CubePlugin = require('@gaotu-fe/webpack-cube-plugin');
const {projectId, projectName} = defaultSettings;
const {REACT_APP_ENV, APP_TYPE, NODE_ENV, SERVE_ENV} = process.env;
const {CASTOKEN} = gctjson;

console.log('NODE_ENV', NODE_ENV)
console.log('CASTOKEN', CASTOKEN)

// 项目配置，具体配置请参考：https://umijs.org/zh-CN/config
export default defineConfig({
    hash: true,
    dva: {
        hmr: true,
    },
    layout: {
        name: defaultSettings.title,
        siderWidth: 208,
        locale: defaultSettings.menu?.locale
    },
    targets: {
        ie: 11,
    },
    dynamicImport: {
        loading: '@/components/PageLoading/index',
    },
    nodeModulesTransform: {
        type: 'none',
    },
    publicPath: '/feitu_feilun/',
    base: '/feilun/',
    outputPath: 'feitu_feilun',
    define: {
        APP_TYPE: APP_TYPE || '',
        REACT_APP_ENV: REACT_APP_ENV || '',
        CASTOKEN: CASTOKEN || '',
        NODE_ENV: NODE_ENV,
        SERVE_ENV: SERVE_ENV,
    },
    openAPI: {
        requestLibPath: "import {request} from 'umi'",
        // 或者使用在线的版本
        schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json",
        // schemaPath: path.join(__dirname, 'oneapi.json'),
        mock: false,
    },
    routes: [
        {
            path: '/',
            redirect: '/welcome',
        },
        {
            path: '/welcome',
            name: '欢迎来到飞轮',
            icon: 'smile',
            component: './Welcome',
            access: 'canReadPageA'
        },
        {
            path: '/abc',
            name: '甄捷思',
            icon: 'table',
            component: './Abc',
        },
        {
            path: '/crud',
            name: '标准代码',
            icon: 'table',
            component: './Crud',
        },
        {
            path: '/crud/edit/:id',
            name: '基础表单编辑页',
            hideInMenu: true,
            component: './Crud/edit'
        },
        {
            path: '/example',
            name: '学习示例',
            icon: 'table',
            routes: [
                {
                    path: '/example/usemodel',
                    name: 'useModel使用',
                    component: './Examples/UseModel',
                }
            ]
        },
        {
            path: '/node',
            name: 'node练习',
            icon: 'table',
            routes: [
                {
                    path: '/node/cats',
                    name: '猫咪管理',
                    component: './Node/Cats',
                }
            ]
        },
        {
            path: '/imis',
            name: '公共IMis配置',
            icon: 'radarChart',
            routes: [
                {
                    path: '/imis/crud',
                    name: '基础列表页',
                    component: './IMis',
                    imisId: 'base_crud',
                },
                {
                    path: '/imis/periodManagement',
                    name: '灵渠-期管理',
                    component: './IMis',
                    imisId: 'periodManagement'
                }
            ]
        }
    ],
    theme: {
        // ...darkTheme,
        'primary-color': defaultSettings.primaryColor,
    },
    // @ts-ignore
    proxy: proxy[SERVE_ENV || 'dev'],
    chainWebpack(memo, {env}) {
        // memo.plugin('dayjsPlugin').use(AntdDayjsWebpackPlugin);
        if (APP_TYPE === 'site' || REACT_APP_ENV === 'test') {
            memo.plugin('gaotu-cube').use(CubePlugin, [
                {
                    name: projectName,
                    projectId,
                    enable: true,
                }
            ])
        }
    }
});
